package svc

import (
	"go-zero-demo/app/datacenter/mq/internal/config"
	"go-zero-demo/pkg/gorm/mysql"
	"go-zero-demo/pkg/rabbitmq"
	"gorm.io/gorm"
)

type ServiceContext struct {
	Config   config.Config
	MySQL    *gorm.DB
	RabbitMq *rabbitmq.Rabbitmq
}

func NewServiceContext(c config.Config) *ServiceContext {
	mysqlClient, err := mysql.New(c.MySQL)
	if err != nil {
		panic(err)
	}

	rabbitMQClient, err := rabbitmq.New(c.RabbitMq)
	if err != nil {
		panic(err)
	}

	return &ServiceContext{
		Config:   c,
		MySQL:    mysqlClient,
		RabbitMq: rabbitMQClient,
	}
}
